package grape.wx.rest;

import grape.common.rest.common.SwaggerConfig;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.ServletContext;
import java.util.Arrays;

/**
 * 将配置单独提出来，以实现被依赖时自动配置
 * Created by yangwei
 * Created at 2020/7/20
 */
@Configuration
@EnableSwagger2
public class WxRestConfig implements SwaggerConfig {
    @Autowired
    private ServletContext servletContext;
    @Value("${spring.application.name}")
    private String applicationName;
    @Bean
    public Docket createWxRestApi() {
        return docket()
                .pathProvider(relativePathProviderForBase("/grape-wx",applicationName,servletContext))
                .groupName("微信应用")
                .apiInfo(apiInfo("Wx"))
                .select()
                //选择controller包
                .apis(basePackage("grape.wx.rest"))
                .apis(withClassAnnotation(Api.class))
                // 内部调用接口不监控
                .paths(notPath("inner"))
                .paths(notPath("/oauth/token"))

                .build().globalOperationParameters(Arrays.asList(authorization()));
    }

}
